package com.youxin.busfoundation.utils;

import java.util.Date;

import com.youxin.foundation.utils.DateUtil;

/**
 * 
 * @author yingde.cao
 *
 */
public class DateTimeBusUtils {
	/**
	 * 获取unix时间秒
	 * @return
	 */
	public static long getTimeSeconds()
	{
		return System.currentTimeMillis()/1000;
	}
	
	public static int getTimeSecondsInt()
	{
		return (int)(System.currentTimeMillis()/1000);
	}
	
	public static int getTimeSecondsInt(long millisecond)
	{
		return (int)(millisecond/1000);
	}
	
	/**
	 * 秒转换为时间
	 * @param seconds
	 * @return
	 */
	public static Date secondsToDate(long seconds)
	{
		return new Date(seconds*1000);
	}
	/**
	 * 获取超时时间
	 * @param date
	 * @return
	 */
	public static Date getExpiresYearDate(Date date)
	{
		boolean isLeapYear=DateUtil.isLeapYear(date);
		int days=isLeapYear?366:365;
		return DateUtil.addDayDate(date, days);
	}
	
	public static Date esLongTimeToDate(long time)
	{		
		if(time==0L){
			return null;
		}
	    long currentTime=System.currentTimeMillis();
	    long tTime=time*1000;
	    if(tTime>currentTime)
	    {
	    	return new Date(time);
	    }
	    return new Date(tTime);
	}
	
	public static String esLongTimeToDateString(long time){
		Date date=esLongTimeToDate(time);
		if(date==null)
		{
			return "";
		}
		return DateUtil.dateToString(date, "yyyy-MM-dd");
	}
	
}
